#include "GEnginePCH.h"
#include "FPSCounter.h"


FPSCounter::FPSCounter(void)
{
}

FPSCounter::~FPSCounter(void)
{	
}
void FPSCounter::Init(void)
{	
	numFPS = 0;
	sumFPS = 0.0f;
	fpsUpdateInterval = 500;
	lastUpdate        = timeGetTime();
	numFrames         = 0;
	fps               = 0;
}


// Called once for every frame
void FPSCounter::UpdateFPS(void)
{
	numFrames++; 
	DWORD currentUpdate = timeGetTime();
	if( currentUpdate - lastUpdate > fpsUpdateInterval )
	{
		fps = numFrames * 1000.0f / (currentUpdate - lastUpdate);
		lastUpdate = currentUpdate;
		numFrames = 0;
		sumFPS += fps;
		++numFPS;
	}
}
float FPSCounter::getFPS(void)
{
	return fps;
}
float FPSCounter::getAvgFPS(void)
{
	return (sumFPS/numFPS);
}